home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-10-04 | 10.4 KB | 356 lines |
- package sub_arctic.anim;
- import sub_arctic.lib.interactor;
-
- /**
- * This class is handy for manipulating transitions both by the user
- * and by the animation agent. It keeps track of when a transition
- * is to occur and allows you to specify a time_interval either in
- * absolute time or in various relative ways.<p>
- *
- * @author Ian Smith
- */
- public class time_interval {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Did they specify a start time.
- */
- protected boolean _specified_start;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Did they specify an end time.
- */
- protected boolean _specified_end;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Did they specify this in terms of duration?
- */
- protected boolean _used_duration;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return if the user specified this interval in terms of duration.
- * @return boolean true if the user specified a duration
- */
- public boolean used_duration() { return _used_duration;};
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return if the user specified a start time for this interval.
- * @return boolean true if the user specified a start time
- */
- public boolean specified_start() { return _specified_start;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return if the user specified an end time for this interval.
- * @return boolean true if the user specified an end time
- */
- public boolean specified_end() { return _specified_end;};
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * If used _used_duration is true, this will contain the duration.
- */
- protected long _duration;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return how long this interval is. Note that if you specified this
- * as a duration, we return it, otherwise we calculate it. We DO NOT
- * check to see if your start and end time are as yet known, so you
- * would be well advised to check _used_duration and valid() to
- * see if its ok to call this.<p>
- *
- * @return long the duration of this interval in milliseconds
- */
- public long duration() {
- if (_used_duration==true) {
- return _duration;
- }
- return _end_time-_start_time;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * We are not in a valid state to be executed until we
- * have both and end and start time.<p>
- *
- * @return boolean true if the user has specified a start and end time
- */
- boolean valid() {
- return (_specified_start && _specified_end);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * What's the current time in milliseconds?<p>
- * @return long the current time
- */
- public static long now() {
- return System.currentTimeMillis();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Use this constant to express that this time interval
- * starts after the start of some other transition.
- */
- public final static int AFTER_START_OF=0;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Use this constant to express that this time interval
- * starts after the end of some other transition.
- */
- public final static int AFTER_END_OF=1;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Start (if known) is here
- */
- protected long _start_time;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * End (if known) is here
- */
- protected long _end_time;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Retrieve the start time of this interval. You may want to
- * check to make sure this interval has a start time before
- * calling this.<p>
- *
- * @return long the start time of this interval in milliseconds
- */
- public long start_time() { return _start_time;};
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Retrieve the end time of this interval. You may want to
- * check to make sure this interval has an end time before
- * calling this. <p>
- *
- * @return long the end time of this interval in milliseconds
- */
- public long end_time() { return _end_time;};
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * If we are relative, who are we relative to?
- */
- protected transition _related_to;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Retrieve what transition we are related to, if any.
- * @return transition the transition to which we are related via
- * AFTER_START_OF or AFTER_END_OF.
- */
- public transition related_to() { return _related_to;};
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * If we are relative, how are we relative? Will be one of the
- * constants AFTER_START_OF or AFTER_END_OF.
- */
- protected int _related_how;
-
- /**
- * This will return one of the relationship constants AFTER_START_OF
- * or AFTER_END_OF if this time_interval is related to another
- * transition. <p>
- *
- * @return int one of the constants AFTER_START_OF and AFTER_END_OF
- */
- public int related_how() { return _related_how;};
-
- /**
- * Return the status of whether or not this time_interval is related
- * to other transitions.<p>
- *
- * @return boolean true if this object is started/ended with respect to
- * other objects.
- */
- boolean relative_to_others() {
- return (related_to()!=null);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /*
- * This delay is the amount of time after the start or end
- * time if they specified a related-to type time_interval.
- */
- protected long _delay;
-
- /**
- * Retrieve the amount of time after the start or end of the
- * other transition if we are related to other transitions.
- * @return long the amount of delay after the start or end of the other
- * transition.
- */
- public long delay() { return _delay;}
-
- /**
- * Set the delay after a relative transition.
- * @param long d the new delay value
- */
- public void set_delay(long d) {_delay = d;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Create one of these puppies... This creates a relative
- * transition... you should supply either AFTER_START_OF
- * and AFTER_END_OF as the "how" parameter. The parm is
- * number of milliseconds after the start or end.<p>
- *
- * @param int how how to be related to the supplied transition
- * @param transition t the transition we are related to
- * @param long parm the amount of delay after the start or end of the
- * related to transition
- */
- public time_interval(int how, transition t,long parm) {
-
- _related_to=t;
- _related_how=how;
- _delay=Math.max(parm,0);
-
- /* they haven't set the values for the object yet, the scheduler will */
- _specified_start=false;
- _specified_end=false;
- _used_duration=false;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Create a time_interval with a known start and end point. These
- * are in milliseconds.<p>
- *
- * @param long start the start time
- * @param long end the end time
- */
- public time_interval(long start, long end) {
- _start_time=start;
- _end_time=end;
- _specified_start=true;
- _specified_end=true;
- _used_duration=false;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Create a time interval that you will fill in the values for later.
- *
- */
- public time_interval() {
- _specified_start=false;
- _specified_end=false;
- _used_duration=false;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set the interval of ending time to be a duration in milliseconds.<p>
- *
- * @param long millis the new duration in milliseconds
- */
- public void set_duration(long millis) {
- _duration=millis;
- _used_duration=true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set the interval ending time to be a particular value in milliseconds.<p>
- *
- * @param long millis the new ending time in milliseconds.
- */
- public void set_ending_time(long millis) {
- _specified_end=true;
- _end_time=millis;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set the ending time to be a particular amount of time from now.
- * @param long millis the new ending point in time (distance from now in
- * milliseconds).
- */
- public void set_ending_time_from_now(long millis) {
- _specified_end=true;
- _end_time=now()+millis;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set the start point to be a known point in milliseconds.<p>
- *
- * @param long millis the new start time in milliseconds
- */
- public void set_start_time(long millis) {
- _specified_start=true;
- _start_time=millis;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set the start point to be a know point in millis from now.<p>
- *
- * @param long millis the new start time (distance from now in milliseconds)
- */
- public void set_start_time_from_now(long millis) {
- _specified_start=true;
- _start_time=now()+ millis;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-